




//处理html tag，让其符合wangeditor
export const handleHtml = (html:string)=>{

    html = html.replace(/<!--[^>]*?>/g,"")
    html = html.replace(/<div[^>]*?>/g,"")
    html = html.replace(/<\/div>/g,"")
    html = html.replace(/<span.*?>/g,"")
    html = html.replace(/<\/span>/g,"")


    if (html.indexOf('<img')==-1){
        return html;
    }
    const node = document.createElement('div');
    node.innerHTML = html;
    let imgs = node.getElementsByTagName('img');
    
    
    for (var i = 0; i < imgs.length; i++) {
        var img = imgs[i];
        const w = img.getAttribute('width');
        if(!w){
            continue
        }
        const h = img.getAttribute('height');
        if(!h){
            continue
        }
        let style = img.getAttribute('style');
        if (style){
            style = style+";width:"+w+"px;height:"+h+'px'
        }else{
            style = "width:"+w+"px;height:"+h+'px'
        }

        img.setAttribute('style',style);
      }

    return node.innerHTML;



}


